package pro1_10.pro1;

public class tree {
    private node root;

    public tree(){
        root = new node();
    }

    public tree(int value){
        root = new node(value);
    }

    public void insert(int value){
        if(root == null){
            root = new node(value);
        }else{
            insertHelp(value,root);
        }
    }

    private void insertHelp(int value, node currNode){
        if(value < currNode.getData()){
            if(currNode.getLeft() == null){
                currNode.setLeft(new node(value));
            }else {
                //左
                insertHelp(value, currNode.getLeft());
            }
        }
        if(value > currNode.getData()){
            if(currNode.getRight() == null){
                currNode.setRight(new node(value));
            }else {
                insertHelp(value,currNode.getRight());
            }
        }
        if(value == currNode.getData()){
            ;
        }
    }

    public void print(){
        if(root == null){
            ;
        } else{
            printHelp(root);
        }
    }

    private void printHelp(node currNode){
        if(currNode != null){
            printHelp(currNode.getLeft());
            System.out.print(currNode.getData() + " ");
            printHelp(currNode.getRight());
        }
    }
}
